<template>
  <div>
    <nav-bar>
      <div slot="left" class="back" @click="backHome">
        <img src="~assets/img/common/back.svg" alt="">
      </div>
      <div slot="center" class="titles">
        <div class="content" v-for="(item, index) in titles" :class="{active: currentIndex === index}"
          @click="contentClick(index)">
          <span>{{item}}</span>
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
  import NavBar from '@/components/common/navbar/NavBar.vue';
  export default {
    name: "DetailsNavBar",
    components: {
      NavBar
    },
    data() {
      return {
        titles: ["商品", "评论", "参数", "推荐"],
        currentIndex: 0
      } 
    },
    methods: {
      contentClick(index) {
        this.currentIndex = index
        this.$emit("navbarClick", index)
      },
      backHome() {
        this.$router.go(-1)
      }
    }
  }
</script>

<style scoped>
  .titles {
    display: flex;
  }
  .content {
    flex: 1;
  }
  .active span {
    color: var(--color-high-text);
    border-bottom: 3px solid var(--color-high-text);
  }
  .back img{
    margin-top: 11px;
  }
</style>